local currentteamid="";
local currentClass="ALL"


function Udkp_MemberDkpFrame_OnLoad()
	UdkpMemberDkpUpdate();
end

function UdkpMemberDkpUpdate()

	totalteamnumber=getn(UDKP_MEMBER_DKP);
	totalMembers=0;
	teamname="";
	FauxScrollFrame_Update(UdkpItemListScrollFrame,0 ,UDKP_NUM_BIDS_TO_DISPLAY,AUCTIONS_BUTTON_HEIGHT);
	for i=1, 10  do
		getglobal("UdkpSiteDkpListButton"..i):Hide();
	end
	for i=totalteamnumber+1,20 do
	getglobal("UdkpTeamFrameListButton"..i):Hide();
	end
	if(totalteamnumber>=1) then
		local offset = FauxScrollFrame_GetOffset(UdkpMemberDkpScrollFrame);
		local m=1;
		
		for i=1,totalteamnumber do
			if(currentteamid~="") then
				if(UDKP_MEMBER_DKP[i]["teamid"]==currentteamid) then
					m=i;
					
				end
			end
			getglobal("UdkpTeamFrameListButton"..i.."Teamid"):SetText(UDKP_MEMBER_DKP[i]["teamid"]);
			
			getglobal("UdkpTeamFrameListButton"..i):SetText(UDKP_MEMBER_DKP[i]["teamname"]);
			
			
		end
		teamname=UDKP_MEMBER_DKP[m]["teamname"];
		local TempMembers= { };
		
		for i=1,getn(UDKP_MEMBER_DKP[m]["Members"]) do
			
			if(UDKP_MEMBER_DKP[m]["Members"][i]["class"]==currentClass or currentClass=="ALL") then
				totalMembers=totalMembers+1;
				table.insert(TempMembers,1,
					{
						["player"] = UDKP_MEMBER_DKP[m]["Members"][i]["player"],
						["class"] = UDKP_MEMBER_DKP[m]["Members"][i]["class"],
						["dkp"] = UDKP_MEMBER_DKP[m]["Members"][i]["dkp"],
					}
				)
			end
		end
		
		for i=1, UDKP_NUM_BIDS_TO_DISPLAY  do
			k = offset + i;
			if ( k > totalMembers ) then
				getglobal("UdkpMemberFrameListButton"..i):Hide();
			else
				getglobal("UdkpSiteDkpListButton"..i):Show();
				getglobal("UdkpSiteDkpListButton" .. i .. "Player"):SetText(TempMembers[k]["player"]);
				getglobal("UdkpSiteDkpListButton" .. i .. "UserClass"):SetText(TempMembers[k]["class"]);
				getglobal("UdkpSiteDkpListButton" .. i .. "Dkp"):SetText(TempMembers[k]["dkp"]);	
			end
		end
	end
	
	FauxScrollFrame_Update(UdkpMemberDkpScrollFrame,totalMembers ,UDKP_NUM_BIDS_TO_DISPLAY,AUCTIONS_BUTTON_HEIGHT);

	getglobal("UdkpMemberDkpHeaderString"):SetText(teamname..UDKP_MESSAGE_TEAM_DKP);
	--getglobal("UdkpRaidHeaderString"):SetText(UDKP_MESSAGE_MEMBER.."|cff1eff00"..TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Notes"].." |r".."(|cffffffff"..totalMembers.."|r:".."|cff1eff00"..onlinemember.."|r/|cff9d9d9d"..offlinemember.."|r)");
	
end

function changeteam(teamid,teamname)
	currentteamid=teamid;
	--getglobal("UdkpMemberDkpHeaderString"):SetText(teamname..UDKP_MESSAGE_TEAM_DKP);
	
  	
	UdkpMemberDkpUpdate()
end

function Udkp_ClassDropDown_OnLoad()
 	UIDropDownMenu_Initialize(this, Udkp_Class_Init);
	UIDropDownMenu_SetSelectedValue(this, "ALL");
end

function Udkp_Class_Init()
	info = {};
	info.text = UDKP_MESSAGE_ALL_CLASS;
	info.value = "ALL";
	info.func = Udkp_ClassDropDown_OnClick;
	UIDropDownMenu_AddButton(info);

	
	info = {};
	info.text = UdkpRaid_Class_Cn["WARRIOR"];
	info.value = UdkpRaid_Class_Cn["WARRIOR"];
	info.func = Udkp_ClassDropDown_OnClick;
	UIDropDownMenu_AddButton(info);
	
	info = {};
	info.text = UdkpRaid_Class_Cn["PALADIN"];
	info.value = UdkpRaid_Class_Cn["PALADIN"];
	info.func = Udkp_ClassDropDown_OnClick;
	UIDropDownMenu_AddButton(info);
	
	info = {};
	info.text = UdkpRaid_Class_Cn["SHAMAN"];
	info.value = UdkpRaid_Class_Cn["SHAMAN"];
	info.func = Udkp_ClassDropDown_OnClick;
	UIDropDownMenu_AddButton(info);
	
	info = {};
	info.text = UdkpRaid_Class_Cn["HUNTER"];
	info.value = UdkpRaid_Class_Cn["HUNTER"];
	info.func = Udkp_ClassDropDown_OnClick;
	UIDropDownMenu_AddButton(info);
	
	info = {};
	info.text = UdkpRaid_Class_Cn["ROGUE"];
	info.value = UdkpRaid_Class_Cn["ROGUE"];
	info.func = Udkp_ClassDropDown_OnClick;
	UIDropDownMenu_AddButton(info);
	
	info = {};
	info.text = UdkpRaid_Class_Cn["DRUID"];
	info.value = UdkpRaid_Class_Cn["DRUID"];
	info.func = Udkp_ClassDropDown_OnClick;
	UIDropDownMenu_AddButton(info);
	
	info = {};
	info.text = UdkpRaid_Class_Cn["WARLOCK"];
	info.value = UdkpRaid_Class_Cn["WARLOCK"];
	info.func = Udkp_ClassDropDown_OnClick;
	UIDropDownMenu_AddButton(info);
	
	info = {};
	info.text = UdkpRaid_Class_Cn["MAGE"];
	info.value = UdkpRaid_Class_Cn["MAGE"];
	info.func = Udkp_ClassDropDown_OnClick;
	UIDropDownMenu_AddButton(info);
	
	info = {};
	info.text = UdkpRaid_Class_Cn["PRIEST"];
	info.value = UdkpRaid_Class_Cn["PRIEST"];
	info.func = Udkp_ClassDropDown_OnClick;
	UIDropDownMenu_AddButton(info);
	
end

function Udkp_ClassDropDown_OnClick()
	UIDropDownMenu_SetSelectedValue(Udkp_ClassDropDown, this.value);
	currentClass=this.value;
	UdkpMemberDkpUpdate();
end



function getCurrentTeamName()


if(Uasit_raidteamid=="") then return "" end
totalteamnumber=getn(UDKP_MEMBER_DKP);
for i=1,totalteamnumber do
	
	if(UDKP_MEMBER_DKP[i]["teamid"]==Uasit_raidteamid) then
		return UDKP_MEMBER_DKP[i]["teamname"]
	end
	
end
return ""
end